package com.zdp.zuul.routeConfig;

import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类描述:
 *
 * @author ZhhengDP
 * @since 2021/8/26
 */
@Configuration
public class RouterConfig {

    /**
     * 自定义路由规则转换器
     * 将形如 servicename-vx的服务名称映射为/vx/servicename的访问路径
     * @return
     */
    @Bean
    public PatternServiceRouteMapper serviceRouteMapper(){
        return new PatternServiceRouteMapper("(?<name>^.+)-(?<version>v.+$)",
                "${version}/${name}");
    }
}
